package com.my.java.concurrent.blocking_quere.delay_queue;

import java.util.Iterator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.DelayQueue;

class EndExam extends Student {

        private DelayQueue<Student> students;
        private CountDownLatch countDownLatch;
        private Thread teacherThread;

        public EndExam(DelayQueue<Student> students, long workTime, CountDownLatch countDownLatch, Thread teacherThread) {
                super("强制收卷", workTime, countDownLatch);
                this.students = students;
                this.countDownLatch = countDownLatch;
                this.teacherThread = teacherThread;
        }

        @Override
        public void run() {
                // TODO Auto-generated method stub

                teacherThread.interrupt();
                Student tmpStudent;
                for (Iterator<Student> iterator2 = students.iterator(); iterator2.hasNext();) {
                        tmpStudent = iterator2.next();
                        tmpStudent.setForce(true);
                        tmpStudent.run();
                }
                countDownLatch.countDown();
        }

}